<template>
  <div class="app-container">
    <div>
      <el-row class="admin-top-g">
        <GButton
          :is-add-show="false"
          :is-edit-show="!!(limits.length >=1 && limits.filter(it => it.FName === '修改').length)"
          :is-del-show="!!(limits.length >=1 && limits.filter(it => it.FName === '删除').length)"
          :is-send-sms-show="true"
          :lists="options"
          :is-settings-show = "lookSetShow"
          @onAdd="addUser"
          @onEdit="editUser"
          @onDelete="delUser"
          @selectSettings="selectSettings"
          @onSendSms="vxeSendSms"
      /></el-row>
      <br>

      <el-row class="common-row">
        <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
          <el-input v-model="keyword" clearable style="width: 260px;" placeholder="请输入关键字" @keyup.native.enter="searchUser" @change="searchUser"/>
          <el-select v-model="fstatus" clearable filterable style="width: 150px;" placeholder="请选择审核状态" @change="searchUser">
            <el-option
              v-for="item in statusList"
              :key="item.fstatus"
              :label="item.fname"
              :value="item.fstatus"/>
          </el-select>
          <el-button type="primary" icon="el-icon-search" @click="searchUser">搜索</el-button>
        </template>

        <el-upload
          v-if="limits.length >=1 && limits.filter(it => it.FName === '导入').length"
          ref="uploadBasic"
          :on-preview="handlePreviewBasic"
          :on-remove="handleRemoveBasic"
          :limit="1"
          :data="upDataBasic"
          :on-exceed="exceedBasic"
          :on-success = "noticeBasic"
          :file-list="fileListBasic"
          :before-upload="beforeAvatarUploadBasic"

          class="upload-demo"
          style="display: inline-block; margin-left: 0px;"
          action="/excel/zyImport"
        >
          <!-- <el-button size="small" type="primary" icon="el-icon-upload">导入</el-button> -->
        </el-upload>

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '导出').length" type="primary" icon="el-icon-my-export" @click="downData">导出</el-button>
        <!-- <el-button type="primary" icon="el-icon-my-updown" @click="handleDownload">下载{{ fmofanName }}模板</el-button> -->

        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '审核').length" type="primary" icon="el-icon-circle-check" @click="check('1')">审核</el-button>
        <el-button v-if="limits.length >=1 && limits.filter(it => it.FName === '反审核').length" type="primary" icon="el-icon-close" @click="check('0')">反审</el-button>

        <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新 </el-button>
        <el-button type="primary" icon="el-icon-top-left" @click="yrYWxq">引入业务需求</el-button>
        <!-- <el-button
          v-if="limits.length >=1 && limits.filter(it => it.FName === '新增').length"
          icon="el-icon-plus"
          type="primary"
          @click="cbAdd">新增</el-button> -->

      </el-row>
    </div>
    <br>
    <el-table
      v-loading="listLoading"
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      ref="fmdTable"
      :data="tableData"
      :summary-method="getSummaries"
      :header-cell-style="tableHeaderStyle"
      :height="tableHeight"
      :header-cell-class-name="markRed"
      show-summary
      class="tableCss"
      element-loading-text="正在加载"
      border
      highlight-current-row
      @cell-dblclick="cellDbClick"
      @selection-change="handleSelectionChange"
      @current-change="salaryCurrentChange">
      <el-table-column
        type="selection"
        width="55"/>
      <template v-for="item in formThead">
        <el-table-column v-if="item.frpttypeflag ==0" :key="item.fid" :label="item.frepcap" :prop="item.frepfld" :width="item.frepwid" align="center" show-overflow-tooltip>

          <template slot-scope="scope">
            <template v-if="item.frephide<=0">
              <template v-if="item.frepfld === 'fstatus'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                <el-tag v-else size="mini" type="danger">未审</el-tag>
              </template>
              <template v-else-if="item.frepfld === 'fisqrname'">
                <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已完成</el-tag>
                <el-tag v-else size="mini" type="danger">未完成</el-tag>
              </template>
              <!-- 佣金比例 -->
              <template v-else-if="item.frepfld==='fyongjinbl'">
                {{ Number(scope.row[item.frepfld])*100 }}  %
              </template>
              <template v-else size="mini">
                {{ scope.row[item.frepfld] }}
              </template>
            </template>
          </template>

        </el-table-column>
      </template>
    </el-table>

    <el-pagination
      v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
      :total="total"
      :page-sizes="pagesizes"
      :page-size="pagesize"
      :current-page.sync="currentPage"
      class="jy-pagination"
      style="text-align: center; margin-top: 20px;"
      background
      layout="sizes, prev, pager, next, total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"/>

    <el-dialog v-el-drag-dialog :visible.sync="addUserModal" title="添加／编辑" width="30%">
      <hr style="height:1px;margin-top:-33px;border:none;border-top:1px solid #ddd;" >
      <el-form v-loading="loadingForm" ref="form" :rules="rules" :inline="true" :model="form" label-width="150px" class="form1">

        <el-row >
          <el-col v-for="item in dialogThead" :span="24" :key="item.fid ">

            <el-form-item :label="item.frepcap" :prop="item.frepfld" >
              <template v-if="item.frepmeg == 1">
                <template v-if=" 'funit' === item.frepfld" >
                  <el-select v-model="form[item.frepfld]" class="select_el" clearable filterable placeholder="请选择">
                    <el-option
                      v-for="item2 in fuzhujichu[item.frepfld]"
                      :key="item2.finterid"
                      :label="item2.fname"
                      :value="item2.fname"/>
                  </el-select>
                </template>

                <template v-else-if=" 'fbrand' === item.frepfld" >
                  <el-select v-model="form[item.frepfld]" class="select_el" clearable filterable placeholder="请选择">
                    <el-option
                      v-for="item2 in brandList"
                      :key="item2.finterid"
                      :label="item2.fname"
                      :value="item2.fname"/>
                  </el-select>
                </template>

              </template>
              <!-- 多文本-->
              <template v-else-if="item.frepmeg == 6" >
                <template >
                  <el-input :rows="3" v-model="form[item.frepfld]" type="textarea" />
                </template>
              </template>
              <!-- 日期框-->
              <template v-else-if="item.frepmeg == 4" >
                <template >
                  <el-date-picker v-model="form[item.frepfld]" style="width:100%" class="date_el" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" />
                </template>
              </template>
              <!-- 禁止编辑-->
              <template v-else-if="item.frepmeg == 5" >
                <template >
                  <el-input v-model="form[item.frepfld]" :disabled="editText"/>
                </template>
              </template>

              <!-- 输入框 -->
              <template v-else >
                <el-input v-model="form[item.frepfld]" />
              </template>
            </el-form-item>
          </el-col>
        </el-row>

        <div class="dialog-footer">
          <el-form-item >
            <el-button :loading="loadingForm" type="primary" @click="confirm" >确认</el-button>
            <el-button @click="addUserModal=false">取消</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>

    <!-- 参数配置 -->
    <el-dialog v-el-drag-dialog :visible.sync="configModal" :close-on-click-modal="false" class="config-dialog">
      <head-table
        :config-list="configList"
        :key-value="key"
        @updateConfigData="getUpdateConfigData" />
    </el-dialog>

    <!-- SQL弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSQLModal" :append-to-body="true" title="执行结果">
      <el-form v-loading="loadingFormSQL" ref="formSQL" :rules="rulesSQL" :model="formSQL" label-width="120px">
        <el-form-item label="SQL语句" prop="gzsql">
          <el-input v-model="formSQL.gzsql" :autosize="{ minRows: 14 }" type="textarea" style="width:400px;"/>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSQL" type="primary" @click="confirmSQL" >确认</el-button>
          <el-button @click="dialogSQLModal=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 下载模板 -->
    <el-dialog :visible.sync="tableSetExcel" title="提示：信息导出" style="width:30%; margin:auto;">
      <el-button type="primary" @click="downloadFile1()">导出</el-button>
    </el-dialog>

    <!-- SendMsg弹窗 -->
    <el-dialog v-el-drag-dialog :visible.sync="dialogSendMsgModal" :append-to-body="true" width="50%" title="发送信息">
      <el-tree
        ref="selectTree"
        :props="defaultProps"
        :data="sendUsrList"
        node-key="id"
        show-checkbox
        @node-click="handleNodeClick"/>
      <br>
      <el-form ref="formSendMsg" :rules="rulesSendMsg" :model="formSendMsg" label-width="40px">
        <el-form-item label="内容" prop="fcontent">
          <el-input v-model="formSendMsg.fcontent" :autosize="{ minRows: 5 }" type="textarea" />
        </el-form-item>
        <el-form-item>
          <el-button :loading="loadingFormSendMsg" type="primary" @click="confirmSendMsg">确认</el-button>
          <el-button @click="dialogSendMsgModal = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :title="importGrid.title"
      :visible.sync="importGrid.fmodal"
      :close-on-click-modal="false"
      :show-close="true"
      class="import-set-modal"
      width="78%"
      @close="closeDialog">
      <div class="search-grid">
        <!-- <vxe-button status="success" icon="vxe-icon-add" content="新增" @click="importGridAdd"/> -->
        <vxe-button status="success" icon="vxe-icon-save" content="保存" @click="importGridSave"/>
        <vxe-button class="import-excel" status="primary" content="导入Excel" @click="toImport" />
        <vxe-button status="success" icon="vxe-icon-delete" content="删除" @click="importGridDel"/>
        <ExcelImport
          :ref="importGrid.excelRefs"
          :data-row="importGrid.dataRow"
          :value-match="importGrid.fieldArr"
          :accept="importGrid.accept"
          @changeExcel="uploadExamFile" />
      </div>
      <vxe-grid
        :id="importGrid.id"
        :ref="importGrid.gridRefs"
        :print-config="{}"
        :import-config="{}"
        :export-config="{}"
        :columns="importGrid.columns"
        :toolbar-config="importGrid.tableToolbar"
        :data="importGrid.data"
        :custom-config="{storage: true}"
        :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
        align="center"
        height="450"
        border
        resizable
        keep-source>
        <template #fcode_edit="{ row }">
          <vxe-input v-model="row.fcode"/>
        </template>
        <template #fname_edit="{ row }">
          <vxe-input v-model="row.fname"/>
        </template>
        <template #fzjqty_edit="{ row }">
          <vxe-input v-model="row.fzjqty"/>
        </template>
        <template #fqty_edit="{ row }">
          <vxe-input v-model="row.fqty"/>
        </template>
      </vxe-grid>
    </el-dialog>

    <!-- 公共弹窗 -->
    <el-dialog
      v-el-drag-dialog
      :visible.sync="fcomDialog.fmodal"
      :close-on-click-modal="false"
      :title= "fcomDialog.title"
      class="config-dialog detail-dialog fcom-dialog"
      @close="closeFcomDialog">
      <div v-if="fcomDialog.isShowToolBar" class="com-dialog-tool">
        <el-input v-model="fcomDialog.fcomKeyword" clearable style="width: 200px;" placeholder="请输入内容" />
        <!-- <el-select v-model="fcomDialog.fdanweibumen" clearable placeholder="请选择部门" @change="searchFcomData">
          <el-option
            v-for="item in fcomDialog.fdanweibumenList"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select> -->
        <el-button type="primary" icon="el-icon-search" @click="searchFcomData">搜索</el-button>
        <el-button v-if="limits.length >= 1 && limits.filter(it => it.FName === '导出').length" type="primary" @click="exportDetailData(fcomDialog.title)">导出</el-button>
        <el-button v-if="limits.length >= 1 && limits.filter(it => it.FName === '修改').length" type="primary" @click="editDialog">编辑</el-button>
        <el-button v-if="limits.length >= 1 && limits.filter(it => it.FName === '删除').length" type="primary" @click="delDialog">删除</el-button>
      </div>
      <el-table
        v-loading="fcomDialog.loading"
        id="fcomTable"
        ref="fcomTable"
        :header-cell-style="tableHeaderStyle"
        :data="fcomDialog.tableData"
        style="margin-top: 10px;"
        max-height="500"
        class="tableCss"
        element-loading-text="正在加载"
        border
        highlight-current-row
        @selection-change="handleFcomDialogChange">
        <el-table-column
          type="selection"
          width="55"/>
        <el-table-column
          v-for="(item, key) in fcomDialog.formThead"
          :key="key"
          :prop="item"
          :label="item"
          align="center">
          <template slot-scope="scope">{{ scope.row[item] }}</template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <el-dialog
      v-el-drag-dialog
      :visible.sync="zsDetailSettings.fdetailModal"
      :close-on-click-modal="false"
      :show-close="true"
      title="详情"
      class="cb-set-modal"
      width="50%">
      <div >
        <div v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length" style="height:50px; margin-bottom: 6px;">
          <el-input
            v-model="zsDetailSettings.fdetailKeyword"
            clearable
            style="width: 260px;"
            placeholder="请输入关键字"
            @keyup.native.enter="cbSearch"
            @change="cbSearch"/>
          <!-- <el-select v-model="zsDetailSettings.fstatus" clearable filterable placeholder="请选择审核状态" @change="cbSearch">
            <el-option
              v-for="item in statusList"
              :key="item.fstatus"
              :label="item.fname"
              :value="item.fstatus"/>
          </el-select> -->
          <el-button type="primary" icon="el-icon-search" @click="cbSearch">搜索</el-button>
          <el-button type="primary" @click="cbConfirm">确认</el-button>
        </div>
        <el-table
          v-loading="zsDetailSettings.fdetailLoading"
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          ref="cbTable"
          :data="zsDetailSettings.fdetailData"
          :header-cell-style="tableHeaderStyle"
          max-height="600"
          class="tableCss single-select-table"
          element-loading-text="正在加载"
          border
          highlight-current-row
          @selection-change="cbHandleSelectionChange"
          @current-change="cbSalaryCurrentChange">
          <el-table-column
            type="selection"
            width="55"/>
          <template v-for="item in zsDetailSettings.detailFormThead">
            <el-table-column
              v-if="item.frpttypeflag ==0"
              :key="item.fid"
              :label="item.frepcap"
              :prop="item.frepfld"
              :width="item.frepwid"
              align="center"
              show-overflow-tooltip>

              <template slot-scope="scope">
                <template v-if="item.frephide<=0">
                  <template v-if="item.frepfld === 'fstatus'">
                    <el-tag v-if="Number(scope.row[item.frepfld]) === 1" size="mini" type="success">已审</el-tag>
                    <el-tag v-else size="mini" type="danger">未审</el-tag>
                  </template>
                  <template v-else size="mini">
                    {{ scope.row[item.frepfld] }}
                  </template>
                </template>
              </template>

            </el-table-column>
          </template>
        </el-table>

        <el-pagination
          v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length"
          :total="zsDetailSettings.total"
          :page-sizes="zsDetailSettings.pagesizes"
          :page-size="zsDetailSettings.pagesize"
          :current-page.sync="zsDetailSettings.currentPage"
          class="jy-pagination"
          style="text-align: center; margin-top: 20px;"
          background
          layout="sizes, prev, pager, next, total"
          @size-change="zSHandleSizeChange"
          @current-change="zSHandleCurrentChange"/>
      </div>
    </el-dialog>

    <el-dialog v-el-drag-dialog :visible.sync="fisJzDialog.addUserModal" title="添加／编辑" width="50%">
      <hr style="height:1px;margin-top:-33px;border:none;border-top:1px solid #ddd;" >
      <el-form v-loading="fisJzDialog.loadingForm" ref="formDialog" :inline="false" :model="fisJzDialog.form" label-width="150px" class="form1">
        <el-form-item label="数量">
          <el-input v-model="fisJzDialog.form['数量']"/>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            :autosize="{ minRows: 2, maxRows: 6 }"
            :rows="2"
            v-model="fisJzDialog.form['备注']"
            type="textarea"/>
        </el-form-item>
        <div class="dialog-footer">
          <el-form-item >
            <el-button :loading="fisJzDialog.loadingForm" type="primary" @click="fisJzConfirm" >确认</el-button>
            <el-button @click="fisJzDialog.addUserModal = false">取消</el-button>
          </el-form-item>
        </div>
      </el-form>
    </el-dialog>

    <!-- 是否是加账详情 -->
    <el-dialog
      v-el-drag-dialog
      :visible.sync="fjzCom.fmodal"
      :close-on-click-modal="false"
      :show-close="true"
      :title= "fjzCom.title"
      class="fjz-set-modal"
      width="70%"
      @close="closeFjzDialog">
      <div style=" margin-top:-20px; ">
        <template v-if="limits.length >=1 && limits.filter(it => it.FName === '查看').length">
          <vxe-grid
            ref="xGrid"
            v-bind="fjzCom.gridOptions"
            :seq-config="{startIndex: (tablePage.currentPage - 1) * tablePage.pageSize}"
            @toolbar-button-click="fjzToolbarButtonClick">
            <template #toolbar_buttons>
              <vxe-input
                v-model="fjzCom.keyword"
                placeholder="搜索"
                prefix-icon="vxe-icon-search"
                clearable
                @keyup.native.enter="getvxetableGenList"/>
              <!-- <vxe-select v-model="fstatus" clearable filterable style="width: 126px;" placeholder="请选择审核状态" @change="getvxetableGenList">
              <vxe-option
                v-for="item in statusList"
                :key="item.fstatus"
                :label="item.fname"
                :value="item.fstatus"/>
            </vxe-select> -->
              <vxe-button status="danger" @click="getvxetableGenList" >搜索</vxe-button>
              <vxe-button
                v-if="limits.length >=1 && limits.filter(it => it.FName === '修改').length"
                status="primary"
                @click="vxeSave()" >保存</vxe-button>
              <vxe-button
                v-if="limits.length >=1 && limits.filter(it => it.FName === '删除').length"
                status="primary"
                @click="vxeDelete()" >删除</vxe-button>
              <vxe-button
                v-if="limits.length >=1 && limits.filter(it => it.FName === '导出').length"
                status="primary"
                @click="vxeExport()" >导出</vxe-button>
              <vxe-button status="primary" @click="refresh()">刷新</vxe-button>
            </template>
            <!-- <template #pager>
              <vxe-pager
                :layouts="['Sizes', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'FullJump', 'Total']"
                :current-page.sync="tablePage.currentPage"
                :page-size.sync="tablePage.pageSize"
                :total="tablePage.total"
                @page-change="handlePageChange"/>
            </template> -->
          </vxe-grid>
        </template>
      </div>
    </el-dialog>

  </div>
</template>
<script>

let FRepKey = ''
let opername = ''
const defaultFormThead = []

import HeadTable from '../salary/headTable/index.vue'
import { configColumn, checkStatus } from '../../api/salary'
import { brand } from '../../mixins/brand'
import { download } from '../../mixins/download.js'
import { common } from '../../mixins/common'
import { pagination } from '../../mixins/pagination'
import { parseTime } from '../../utils/index'
// import { tableConfig, apiSql, vxetableGenAdd, vxetableGenList, cenShuSave, vxetableBillConfig, apiFileSave, downFileUrl } from '../../api/account'
import { tableConfig, apiSql, vxetableBillConfig, apiFileSave, downFileUrl } from '../../api/account'
import { QdhtBaojia, FYWImportJZ, genAdd, genDel, genList } from '../../api/gen'
import { sendsms, beijianTree } from '../../api/peijian'
import { FhouxuJZ, FhouxuJZDel, FhouxuJZSave } from '../../api/xmbj'
import { XLSXOBJ } from '../../utils/XLSXExportExcel'
import '../../styles/common.scss'
import '../../styles/svg.scss'

import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'

import VXETablePluginShortcutKey from 'vxe-table-plugin-shortcut-key'
import '../../styles/vxetable.scss'

VXETable.use(VXETablePluginShortcutKey, {
  setting: {
    'table.edit.tab.rightMove': 'Enter',
    'table.edit.tab.leftMove': 'shift + Tab'

  }
})

export default {
  name: 'Index',
  components: {
    HeadTable
  },
  filters: {
    parseTime(time, type) {
      return parseTime(time, type)
    }
  },
  mixins: [download, common, pagination, brand],
  data() {
    return {
      fstatus: '', // 状态
      // 下拉列表
      statusList: [
        {
          fstatus: 0,
          fname: '全部'
        },
        {
          fstatus: 1,
          fname: '未审'
        },
        {
          fstatus: 2,
          fname: '已审'
        },
        {
          fstatus: 5,
          fname: '已完成'
        }
      ],
      // 明细公共弹窗
      fcomDialog: {
        info: [
          { field: 'fjiazhangcbcg', title: '加账采购详情', FRepKey: 26005, fdanweibumen: 1, isShowToolBar: true },
          { field: 'fjiazhangcbjs', title: '加账技术详情', FRepKey: 26023, fdanweibumen: 2, isShowToolBar: true },
          { field: 'fjiazhangcbqt', title: '加账其他详情', FRepKey: 26025, fdanweibumen: 3, isShowToolBar: true },
          // { field: 'fisjiazhang', title: '是否有加账详情', FRepKey: 14009, fdanweibumen: 0, isShowToolBar: true }
          { field: 'fisjiazhang', title: '是否有加账详情', FRepKey: 3001002, fdanweibumen: 0, isShowToolBar: true }

        ],
        fcomKeyword: '',
        fbrand: '',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        fjzdetail: 1, // 是否加账处理
        FRepKey: 0,
        isShowToolBar: false,
        title: '',
        fjybjbillno: '',
        keyword: '',
        fmodel: '',
        fmodal: false,
        loading: false,
        tableData: [],
        formThead: [],
        // 是否加账
        cjDetail: {
          fmodel: '',
          fbrand: '',
          fjybjbillno: '',

          isShowToolBar: false,
          title: '',
          FRepKey: 0,
          fdanweibumen: '',

          header: [], // 表头字段（值）
          headerKeys: [], // 表头字段（键） filterVal
          listData: [], // 表体数据
          // keyword: '',
          fmodal: false, // 1
          fdetailKeyword: '', // 1
          fdetailLoading: false, // 1
          detailFormThead: [], // 1
          detailDialogThead: [],
          fdetailData: [], // 1
          fdetailList: []
        }
      },

      importGrid: {
        rows: '',
        fmodel: '',
        fbrand: '',
        title: '业务需求市场部（导入）',
        excelRefs: 'importExcel', // ExcelImport
        dataRow: 0, // 数据开始行 默认从第0行开始
        fieldArr: ['fcode', 'fname', 'fzjqty', 'fqty'], // 数据列 必须与excel中的表列顺序相对应
        valueTitle: ['代码', '名称', '装机数', '数量'],
        accept: '.xls,.xlsx',
        id: 'import-grid',
        gridRefs: 'importTable', // vxe-grid
        fmodal: false,
        data: [],
        columns: [
          { type: 'checkbox', width: 50 },
          { type: 'seq', width: 60 },
          { field: 'fcode', title: '代码', editRender: {}, slots: { edit: 'fcode_edit' }},
          { field: 'fname', title: '名称', editRender: {}, slots: { edit: 'fname_edit' }},
          { field: 'fzjqty', title: '装机数', editRender: {}, slots: { edit: 'fzjqty_edit' }},
          { field: 'fqty', title: '数量', editRender: {}, slots: { edit: 'fqty_edit' }}
        ]
      },
      dialogSendMsgModal: false,
      loadingFormSendMsg: false,
      userList: [],
      sendUsrList: [],
      formSendMsg: {
      },
      rulesSendMsg: {
      },
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      handleNodeClick(data) {
        console.log(data)
      },
      value: '',
      options: [],
      FRepKey: '',
      keyword: '',
      fdeleted: '',
      fdeletedList: [

      ],
      fdeletedListDiaL: [

      ],
      gapTime: '',
      start_time: '',
      end_time: '',

      // 表头、表格设置
      tableData: [],
      tableList: [],
      defaultFormThead: [],
      formThead: defaultFormThead,
      dialogThead: [],
      curData: {},

      listLoading: false,
      list: [],
      configModal: false,
      configLoading: false,

      loadingForm: false,
      configList: [],
      key: 0,
      // SQL弹窗
      dialogSQLModal: false,
      loadingFormSQL: false,
      formSQL: {
        gzsql: ''
      },
      rulesSQL: {

      },

      form: {},
      rules: {

      },
      addUserModal: false,
      // loadingForm: false

      fileList: [],

      // 批量删除
      checkData: [],
      selectedData: [],

      // 用户菜单
      menusList: [],
      limits: [],
      fuzhujichu: {},
      userKey: '',
      fmofanName: '',

      bmwzList: [ // 部门位置
        {
          finterid: 0,
          fname: '钢壳'
        },
        {
          finterid: 1,
          fname: '铝壳'
        },
        {
          finterid: 2,
          fname: '14500'
        }
      ],

      upData: {},
      fdeptname: '', // 部门
      bmList: [], // 部门
      xlList: [], // 学历
      zwList: [], // 职务
      xbList: [], // 性别
      lzztList: [],
      fileListBasic: [],
      baseList: [],
      upDataBasic: {},

      detail: '',
      detailVisible: false,
      editText: false,
      tableSetExcel: false,
      lookSetShow: false,
      oriColumnData: [],
      setConfigData: [],

      // 是否加账编辑
      fisJzDialog: {
        dialogObj: {
          row: '',
          fbillno: '',
          fisqrname: 0, // 1 已完成
          fstatus: 0 // 1已审 0未审
        }, // 是否审核
        addUserModal: false,
        loadingForm: false,
        // rules: [],
        checkData: [],
        selectedData: [],
        form: {
          '数量': '',
          '备注': ''
        }
      },

      // 装试车间(辅材)    ---- 装试
      zsDetailSettings: {
        fstatus: 2,
        header: [], // 表头字段（值）
        headerKeys: [], // 表头字段（键） filterVal
        listData: [], // 表体数据
        fmodel: '',
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '0',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        // keyword: '',
        fdetailModal: false, // 1
        fdetailKeyword: '', // 1
        fdetailLoading: false, // 1
        detailFormThead: [], // 1
        detailDialogThead: [],
        fdetailData: [], // 1
        fdetailList: [],
        // 页脚
        total: 0,
        pagesize: 10,
        pagesizes: [10, 20, 50, 100],
        currentPage: 1
      },
      tablePage: {
        total: 0,
        currentPage: 1,
        pageSize: 20
      },
      vxeDisabled: false,

      gridKeyword: '',

      gridDialogThead: [],
      columnHeaderData: [],
      columnData: [],
      // 1
      gridOriColumnData: [],
      gridColumnData: [],
      gridFormThead: [],
      opername: '',
      // 基础设置
      baseSettings: {
        title: '基础设置-加账采购成本',
        fbaseModal: false,
        fbaseKeyword: '',
        fbaseLoading: false,
        fbaseData: [],
        fbrand: 'WINGD',
        fbrandList: [
          { label: 'WINGD', value: 'WINGD' },
          { label: 'MAN', value: 'MAN' }
        ],
        fdanweibumen: '1',
        fdanweibumenList: [
          { label: '采购部', value: '1' },
          { label: '技术中心', value: '2' },
          { label: '其他部门', value: '3' },
          { label: '全部', value: '0' }
        ],
        fbaseTableColumn: [
          { type: 'checkbox', width: 50 },
          // { type: 'seq', width: 60 },
          { field: 'fbrand', title: '品牌', editRender: {}, slots: { edit: 'fbrand_edit' }},
          { field: 'fcode', title: '代码', editRender: {}, slots: { edit: 'fcode_edit' }},
          { field: 'fprodno', title: '机型', editRender: {}, slots: { edit: 'fprodno_edit' }},
          { field: 'fname', title: '名称', editRender: {}, slots: { edit: 'fname_edit' }},
          // { field: 'ffaxamount', title: '含税金额', editRender: {}, slots: { edit: 'ffaxamount_edit' }},
          { field: 'fywqty', title: '数量', editRender: {}, slots: { edit: 'fywqty_edit' }},
          { field: 'fzjqty', title: '单位', editRender: {}, slots: { edit: 'fzjqty_edit' }},
          { field: 'fnote', title: '备注', editRender: {}, slots: { edit: 'fnote_edit' }}
          // { field: 'fdanweibumen', title: '部门', editRender: {}, slots: { edit: 'fdanweibumen_edit' }}
        ],
        formConfig: {
          data: {
            keyword: ''
          }
        },
        tableToolbar: {
          size: 'mini',
          buttons: [
            { code: 'search', status: 'primary', name: '搜索' },
            // { code: 'myInsert', visible: true, name: '新增', status: 'success' },
            { code: 'mySave', visible: true, name: '保存', status: 'success' },
            { code: 'myDelete', name: '删除', status: 'primary' },
            { code: 'myExport', visible: true, name: '导出', status: 'primary' }
            // { code: 'myFresh', name: '刷新', status: 'primary' }
          ]
        // refresh: true
        // import: true,
        // export: true,
        // print: true,
        // zoom: true,
        // custom: true
        }
      },
      fyjDisabled: false,

      fjzCom: {
        formThead: [],
        header: [],
        listData: [],
        headerKeys: [],
        oriColumnData: [],
        columnData: [],

        fmodal: false,
        row: '',
        fmodel: '',
        fbrand: '',
        fjybjbillno: '',
        fbillnoentry: '',

        title: '是否是加账详情',
        // fmodal: false,
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 20
        },
        keyword: '',
        vxeDisabled: false,
        gridOptions: {
          border: true,
          showHeaderOverflow: true,
          showOverflow: true,
          showFooterOverflow: true,
          keepSource: true,
          autoResize: true,
          resizable: true,

          height: this.heightGD(),
          showFooter: true,
          round: true,
          size: 'mini',

          id: 'full_edit_1',
          rowId: 'id',
          rowConfig: {
            isHover: true
          },
          // columnConfig: {
          //   resizable: true
          // },

          // 自定义列配置项
          customConfig: {
            storage: true,
            checkMethod: this.checkColumnMethod
          },

          keyboardConfig: {
            isEnter: true,
            isArrow: true
          },

          // formConfig: {
          //   titleWidth: 100,
          //   titleAlign: 'right',
          //   items: [
          //     // { field: 'name', title: '名称', span: 8, titlePrefix: { message: 'app.body.valid.rName', icon: 'vxe-icon-info-circle-fill' }, itemRender: { name: '$input', props: { placeholder: '请输入名称' }}},
          //     // { field: 'email', title: '邮件', span: 8, titlePrefix: { useHTML: true, message: '点击链接：<a class="link" href="https://vxetable.cn" target="_blank">vxe-table官网</a>', icon: 'vxe-icon-question-circle-fill' }, itemRender: { name: '$input', props: { placeholder: '请输入邮件' }}},
          //     // { field: 'nickname', title: '昵称', span: 8, itemRender: { name: '$input', props: { placeholder: '请输入昵称' }}}
          //     // { field: 'role', title: '角色', span: 8, folding: true, itemRender: { name: '$input', props: { placeholder: '请输入角色' }}},
          //     // { field: 'sex', title: '性别', span: 8, folding: true, titleSuffix: { message: '注意，必填信息！', icon: 'vxe-icon-info-circle-fill' }, itemRender: { name: '$select', options: [] }},
          //     // { field: 'age', title: '年龄', span: 8, folding: true, itemRender: { name: '$input', props: { type: 'number', min: 1, max: 120, placeholder: '请输入年龄' }}}
          //     // { span: 24, align: 'center', collapseNode: true, itemRender: { name: '$buttons', children: [{ props: { type: 'submit', content: '搜索', status: 'primary' }}, { props: { type: 'reset', content: '重置' }}] }}
          //   ]
          // },

          toolbarConfig: {
            custom: true,
            buttons: [
              { code: 'myInsert', name: '新增', icon: 'vxe-icon-square-plus', status: 'success' },
              { code: 'myDelete', name: '删除', icon: 'vxe-icon-delete', status: 'success' },
              { code: 'mySave', name: '保存', icon: 'vxe-icon-save', status: 'success' }
            // { code: 'myInsertTZ', name: '新增跳转', icon: 'vxe-icon-square-plus', status: 'success' }
            // { code: 'myOper', name: '操作', icon: 'vxe-icon-square-down', status: 'success', slots: 'default', dropdowns: [{ code: 'myAA', 'name': 'AA', status: 'info', icon: 'vxe-icon-square-plus-fill' }, { code: 'myBB', 'name': 'BB', status: 'info', icon: 'vxe-icon-square-plus-fill' }] }
            ],
            slots: {
              buttons: 'toolbar_buttons'
            }

          },
          columns: [],
          data: [],

          checkboxConfig: {
          // labelField: 'id',
            reserve: true,
            highlight: true,
            range: true
          },

          editConfig: {
            trigger: 'click',
            mode: 'row',
            showStatus: true, // 是否显示单元格新增与修改状态
            showIcon: false // 是否显示列头编辑图标
          // activeMethod: this.activeRowMethod
          }

        }
      }

    }
  },
  async mounted() {
    this.userKey = this.$route.meta.FRepKey
    FRepKey = this.$route.meta.FRepKey
    this.upDataBasic.db = this.globalDb.db
    opername = decodeURIComponent(this.globalDb.fname)
    this.opername = decodeURIComponent(this.globalDb.fname)

    this.upDataBasic.FRepKey = this.$route.meta.FRepKey
    this.lookSetShow = JSON.parse(localStorage.getItem('flookSet'))

    this.upData.db = this.globalDb.db
    this.fmofanName = this.$route.meta.title

    await this.getAllData()
    // 获取单位
    // await this.getunit()

    // 菜单列表（权限）
    const menuRes = JSON.parse(localStorage.getItem('setMenuData'))
    this.menusList = menuRes
    if (menuRes.length >= 1) {
      menuRes.map(it => {
        it.children.map(item => {
          if (item.fobjectid === this.userKey) {
            this.$set(this, 'limits', item.child)
          }
        })
      })
    }

    // 获取辅助资料
    const fuzhujichu = JSON.parse(localStorage.getItem('fuzhujichuData'))
    this.$set(this, 'fuzhujichu', fuzhujichu)
    // 参数设置
    const setConfigData = JSON.parse(localStorage.getItem('setConfigData'))
    this.$set(this, 'setConfigData', setConfigData)
    // console.log(setConfigData.fsethuilv)
    // console.log(this.headerKeys, ' this.headerKeys  111')
  },
  methods: {
    // 按钮点击
    async fjzToolbarButtonClick({ code }) {
      const $grid = this.$refs.xGrid
      const { insertRecords, removeRecords, updateRecords } = $grid.getRecordset()
      const { tableData } = $grid.getTableData()
      switch (code) {
        case 'myInsert':
          $grid.insert({

          })
          break
          // 保存
        case 'mySave':
          setTimeout(async() => {
            if (insertRecords.length === 0 && updateRecords.length === 0 && removeRecords.length === 0) {
              VXETable.modal.message({ content: `新增 ${insertRecords.length} 条，更新 ${updateRecords.length} 条`, status: 'warning' })
              return
            }
            console.log(insertRecords, removeRecords, updateRecords, insertRecords.length > 0, updateRecords.length > 0, removeRecords.length > 0)
            try {
              // const res = await vxetableGenAdd({ FRepKey, opername: this.opername, insertRecords, updateRecords, removeRecords })
              const res = await FhouxuJZSave({
                fbrand: this.fjzCom.fbrand,
                FRepKey,
                opername: this.opername,
                insertRecords,
                updateRecords,
                removeRecords,
                row: this.fjzCom.row,
                data: tableData
              })
              if (res.Error === 0) {
                this.getvxetableGenList()
                VXETable.modal.message({ content: `新增 ${insertRecords.length} 条，更新 ${updateRecords.length} 条`, status: 'success' })
              } else {
                VXETable.modal.message({ content: res.Message, status: 'error' })
              }
            } catch (error) {
              console.log(error)
            }
          })
          break
          // 删除
        case 'myDelete':
          if ($grid.getCheckboxRecords().length === 0) {
            VXETable.modal.message({ content: `请选中一行`, status: 'warning' })
            return
          }
          // setTimeout(async() => {
          //   const { removeRecords } = $grid.getRecordset()

          //   $grid.removeCheckboxRow()
          //   const res = await vxetableGenAdd({ FRepKey, opername: this.opername, removeRecords })
          //   if (res.Error === 0) {
          //     VXETable.modal.message({ content: ` 删除 ${removeRecords.length} 条`, status: 'success' })
          //     this.getvxetableGenList()
          //   }

          // $grid.clearSelected()
          // $grid.clearCheckboxRow()
          // })

          try {
            const res = await FhouxuJZDel({
              fbrand: this.fjzCom.fbrand,
              FRepKey,
              opername: this.opername,
              insertRecords,
              updateRecords,
              removeRecords: $grid.getCheckboxRecords(),
              row: this.fjzCom.row
            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              this.brandModel = false
              await this.getvxetableGenList()
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
          break

        case 'myInsertTZ':

          break

        case 'myAA':
          VXETable.modal.message({ content: '新增', status: 'success' })
          break
      }
    },
    // 导出
    async vxeExport() {
      await this.getJzAllData()
      await this.exportData()
    },
    // 删除
    async vxeDelete() {
      const $grid = this.$refs.xGrid
      const { insertRecords, updateRecords } = $grid.getRecordset()
      if ($grid.getCheckboxRecords().length === 0) {
        VXETable.modal.message({ content: `请选中一行`, status: 'warning', zIndex: 9999 })
        return
      }
      try {
        const res = await FhouxuJZDel({
          fbrand: this.fjzCom.fbrand,
          FRepKey,
          opername: this.opername,
          insertRecords,
          updateRecords,
          removeRecords: $grid.getCheckboxRecords(),
          row: this.fjzCom.row
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          this.brandModel = false
          await this.getvxetableGenList()
        } else {
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
      // FhouxuJZDel
    },

    // 保存
    async vxeSave() {
      const $grid = this.$refs.xGrid
      const { tableData } = $grid.getTableData()
      const { insertRecords, removeRecords, updateRecords } = $grid.getRecordset()
      if (insertRecords.length === 0 && updateRecords.length === 0 && removeRecords.length === 0) {
        VXETable.modal.message({ content: ` 更新 ${updateRecords.length} 条`, status: 'warning' })
        return
      }
      // 修改时 是否已审核
      if (updateRecords.length > 0) {
        const isFstatus = updateRecords.filter(it => Number(it.fstatus) === 1)
        if (isFstatus.length) {
          this.$message({
            message: '已审核，不能修改！',
            type: 'error'
          })
          return
        }
      }

      // console.log(insertRecords, removeRecords, updateRecords, insertRecords.length > 0, updateRecords.length > 0, removeRecords.length > 0)
      try {
        // await vxetableGenAdd({ FRepKey, opername: this.opername, insertRecords, updateRecords, removeRecords })
        // const res = await cenShuSave({ FRepKey, opername: this.opername, insertRecords, updateRecords, removeRecords })
        const res = await FhouxuJZSave({
          fbrand: this.fjzCom.fbrand,
          FRepKey: 3001002,
          opername: this.opername,
          insertRecords,
          updateRecords,
          removeRecords,
          data: this.fjzCom.row,
          tableData
        })
        if (res.Error === 0) {
          this.$message({
            type: 'success',
            message: res.Message
          })
        } else {
          this.$message({
            type: 'error',
            message: res.Message
          })
        }
        this.getvxetableGenList()
      } catch (error) {
        console.log(error)
      }

      VXETable.modal.message({ content: ` 更新 ${updateRecords.length} 条`, status: 'success' })
    },
    // 分页
    handlePageChange({ currentPage, pageSize }) {
      this.fjzCom.tablePage.currentPage = currentPage
      this.fjzCom.tablePage.pageSize = pageSize
      this.getvxetableGenList()
    },
    // 内容列表
    async getvxetableGenList() {
      // const param = { FRepKey, keyword: this.keyword, fstatus: this.fstatus, page: this.tablePage.currentPage, pageSize: this.tablePage.pageSize }
      // const res = await vxetableGenList(param)
      const param = {
        keyword: this.fjzCom.keyword,
        FRepKey: 3001002,
        opername,
        data: this.fjzCom.row,
        fmodel: this.fjzCom.fmodel,
        fbrand: this.fjzCom.fbrand,
        fjybjbillno: this.fjzCom.fjybjbillno
      }
      const res = await FhouxuJZ(param)
      setTimeout(() => {
        this.fjzCom.tablePage.total = res.total || 0
        this.fjzCom.gridOptions.data = res.Data
      }, 500)
    },
    // 内容列表
    async getJzAllData() {
      const $grid = this.$refs.xGrid
      const getCheckboxRecordsData = $grid.getCheckboxRecords()
      const { fullData } = $grid.getTableData()
      // const param = { FRepKey, keyword: this.keyword, fstatus: this.fstatus, page: this.tablePage.currentPage, pageSize: this.tablePage.total }
      // const res = await vxetableGenList(param)
      // const param = {
      //   keyword: this.fjzCom.keyword,
      //   FRepKey: 3001002,
      //   opername,
      //   data: this.fjzCom.row,
      //   fmodel: this.fjzCom.fmodel,
      //   fbrand: this.fjzCom.fbrand,
      //   fjybjbillno: this.fjzCom.fjybjbillno
      // }
      // const res = await FhouxuJZ(param)
      // setTimeout(() => {
      // this.tablePage.total = res.total
      // this.gridOptions.data = res.Data
      // 获取显示表体数据
      // console.log(res, ' res  getJzAllData')
      // console.log(this.fjzCom.gridOptions.data, ' this.fjzCom.gridOptions.data')
      // console.log(this.fjzCom.header, ' this.fjzCom.header')
      // console.log(this.fjzCom.headerKeys, ' this.fjzCom.headerKeys')

      /*
      const listData = res.Data.slice()
      // console.log(this.total, ' this.total')
      // console.log(this.listData, ' this.listData')
      listData.map((item, index) => {
        this.listData[index] = {}
        this.headerKeys.map(it => {
          this.listData[index][it] = item[it]
        })
      })
      */

      this.fjzCom.listData = []
      if (!getCheckboxRecordsData.length) {
        this.fjzCom.listData = fullData
      } else {
        this.fjzCom.listData = getCheckboxRecordsData
      }
      this.header = this.fjzCom.header
      this.headerKeys = this.fjzCom.headerKeys
      this.listData = this.fjzCom.listData
      this.filename = parseTime(new Date().getTime(), '{y}-{m}-{d}__{h}{i}') + '市场需求后续加账详情'
    },
    // ssssssssssssssssssssssssssssssssssss
    // 高度
    heightGD() {
      return (document.body.offsetHeight - 150) + 'px'
    },
    // // 保存
    // async vxeSave() {
    //   const $grid = this.$refs.xGrid
    //   const { insertRecords, removeRecords, updateRecords } = $grid.getRecordset()
    //   const { tableData } = $grid.getTableData()
    //   console.log(insertRecords, removeRecords, updateRecords, 111111, this.formData)
    //   console.log(tableData, ' 333 tableData')
    //   if (insertRecords.length === 0 && updateRecords.length === 0 && removeRecords.length === 0) {
    //     VXETable.modal.message({ content: `新增 ${insertRecords.length} 条，更新 ${updateRecords.length} 条`, status: 'warning' })
    //     return
    //   }
    //   // 修改时 是否已审核
    //   if (updateRecords.length > 0) {
    //     const isFstatus = updateRecords.filter(it => Number(it.fstatus) === 1)
    //     if (isFstatus.length) {
    //       this.$message({
    //         message: '已审核，不能修改！',
    //         type: 'error'
    //       })
    //       return
    //     }
    //   }

    //   const selectData = $grid.getCheckboxRecords()
    //   if (!selectData.length) {
    //     this.$message({
    //       type: 'error',
    //       message: '请选中数据'
    //     })
    //     return
    //     // VXETable.modal.message({ content: `新增 ${insertRecords.length} 条，更新 ${updateRecords.length} 条`, status: 'success' })
    //   }

    //   const res = await FhouxuJZSave({
    //     FRepKey: 3001002,
    //     opername: this.opername,
    //     insertRecords,
    //     updateRecords,
    //     removeRecords,
    //     data: this.fcomDialog.cjDetail.row,
    //     tableData
    //   })

    //   console.log(res, ' res xxx')
    //   if (res.Error === 0) {
    //     this.$message({
    //       type: 'success',
    //       message: res.Message
    //     })
    //     // await this.getAllData()
    //   } else {
    //     this.$message({
    //       type: 'error',
    //       message: res.Message
    //     })
    //   }
    //   this.confirmVisible = false

    //   // const insertRecordsArr = []
    //   // insertRecords.map(it => {
    //   //   if (it.fmodel) {
    //   //     insertRecordsArr.push(it)
    //   //   }
    //   // })

    //   // const tableDataArr = []
    //   // tableData.map(it => {
    //   //   if (it.fmodel) {
    //   //     tableDataArr.push(it)
    //   //   }
    //   // })

    //   // VXETable.modal.message({ content: `新增 ${insertRecords.length} 条，更新 ${updateRecords.length} 条`, status: 'success' })
    // },
    // // 按钮点击
    // async fbaseToolBarButtonClick({ code }) {
    //   const $grid = this.$refs.fbaseTable
    //   const getCheckboxRecordsData = $grid.getCheckboxRecords()
    //   const { insertRecords, removeRecords, updateRecords } = $grid.getRecordset()
    //   const { tableData } = $grid.getTableData()
    //   switch (code) {
    //     case 'search':
    //       this.getvxetableGenList()
    //       break
    //     case 'myInsert':
    //       $grid.insertAt(-1, -1)
    //       break
    //     case 'mySave':
    //       if (insertRecords.length === 0 && updateRecords.length === 0 && removeRecords.length === 0) {
    //         VXETable.modal.message({ content: `新增 ${insertRecords.length} 条，更新 ${updateRecords.length} 条`, status: 'warning', zIndex: 99999 })
    //         return
    //       }
    //       try {
    //         const res = await FhouxuJZSave({
    //           fbrand: this.baseSettings.fbrand,
    //           FRepKey,
    //           opername: this.opername,
    //           insertRecords,
    //           updateRecords,
    //           removeRecords,
    //           row: this.fcomDialog.cjDetail.row,
    //           data: tableData
    //         })
    //         if (res.Error === 0) {
    //           this.$message({
    //             message: res.Message,
    //             type: 'success'
    //           })
    //           this.brandModel = false
    //           await this.getvxetableGenList()
    //         } else {
    //           this.$message({
    //             message: res.Message,
    //             type: 'error'
    //           })
    //         }
    //       } catch (error) {
    //         console.log(error)
    //       }
    //       break
    //     case 'myDelete':
    //       if ($grid.getCheckboxRecords().length === 0) {
    //         VXETable.modal.message({ content: `请选中一行`, status: 'warning', zIndex: 9999 })
    //         return
    //       }
    //       // setTimeout(async() => {
    //       //   $grid.removeCheckboxRow()
    //       // })
    //       try {
    //         const res = await FhouxuJZDel({
    //           fbrand: this.baseSettings.fbrand,
    //           FRepKey,
    //           opername: this.opername,
    //           insertRecords,
    //           updateRecords,
    //           removeRecords: $grid.getCheckboxRecords(),
    //           row: this.fcomDialog.cjDetail.row
    //           // data: tableData
    //         })
    //         if (res.Error === 0) {
    //           this.$message({
    //             message: res.Message,
    //             type: 'success'
    //           })
    //           this.brandModel = false
    //           await this.getvxetableGenList()
    //         } else {
    //           this.$message({
    //             message: res.Message,
    //             type: 'error'
    //           })
    //         }
    //       } catch (error) {
    //         console.log(error)
    //       }
    //       break
    //     case 'myExport':
    //       this.appendName = '基础设置' + this.baseSettings.fbrand
    //       this.baseSettings.fbaseTableColumn.slice(1).map((item, idx) => {
    //         for (const i in item) {
    //           if (i === 'field') {
    //             this.headerKeys[idx] = item.field
    //           }
    //           if (i === 'title') {
    //             this.header[idx] = item.title
    //           }
    //         }
    //       })
    //       this.listData = []
    //       if (!getCheckboxRecordsData.length) {
    //         if (this.baseSettings.fbaseData.length) {
    //           this.baseSettings.fbaseData.map((item, idx) => {
    //             this.listData[idx] = {}
    //             for (const i in item) {
    //               if (this.headerKeys.includes(i)) {
    //                 this.listData[idx][i] = item[i]
    //               }
    //             }
    //           })
    //         }
    //       } else {
    //         this.listData = getCheckboxRecordsData
    //       }
    //       // console.log(this.listData, ' this.listData')
    //       // console.log(this.headerKeys, ' this.headerKeys')
    //       // console.log(this.header, ' this.header')
    //       this.headerKeys = [
    //         'fbrand',
    //         'fcode',
    //         'fprodno',
    //         'fname',
    //         'fywqty',
    //         'fzjqty',
    //         'fnote'
    //       ]
    //       this.exportData()
    //       break
    //     case 'myFresh':
    //       this.getvxetableGenList()
    //       break
    //   }
    // },
    // fbaseToolbarToolClickEvent({ code }) {
    //   const $grid = this.$refs.fbaseTable
    //   switch (code) {
    //     case 'myPrint':
    //       $grid.print()
    //       break
    //   }
    // },
    markRed({ row, rowIndex, column, columnIndex }) {
      let markRed = ''
      switch (column.property) {
        case 'fisjiazhang': // 是否有加账
          markRed = 'markRed'
          break
        default:
          markRed = ''
          break
      }
      return markRed
    },
    async cbSearch() {
      await this.getZsBodyData()
      await this.getZsHeadData()
    },
    async cbConfirm() {
      console.log(this.rows, ' this.rows')
      if (this.rows && this.rows.length) {
        // console.log(this.rows, ' this.rows')
        this.fbillno = this.rows[0].fbillno
        this.fmodel = this.rows[0].fmodel
        this.inputVal = this.rows[0].fhtpower
        this.cbModal = false
        try {
          const res = await QdhtBaojia({
            FRepKey,
            opername,
            data: this.rows[0]
          })
          if (res.Error === 0) {
            this.$message({
              type: 'success',
              message: res.Message
            })
            this.$refs.cbTable.clearSelection()
            this.zsDetailSettings.fdetailModal = false
            await this.getAllData()
          } else {
            this.$message({
              type: 'error',
              message: res.Message
            })
          }
        } catch (error) {
          console.log(error)
        }
      } else {
        this.$message({
          type: 'error',
          message: '请选中一行数据'
        })
      }
    },
    async cbAdd() {
      this.$router.push('/baojia/marketHxAdd?key=30010')
      return
    },
    cbHandleSelectionChange(rows) {
      if (rows.length) {
        this.rows = rows
      }
      if (rows.length > 1) {
        this.$refs.cbTable.clearSelection()
        this.$refs.cbTable.toggleRowSelection(rows.pop())
      }
    },
    cbSalaryCurrentChange() {

    },
    async yrYWxq() {
      this.zsDetailSettings.fdetailModal = true
      await this.getZsBodyData()
      await this.getZsHeadData()
    },
    async zSHandleSizeChange(val) {
      this.zsDetailSettings.currentPage = 1
      this.zsDetailSettings.pagesize = val
      await this.getZsBodyData()
      await this.getZsHeadData()
    },
    async zSHandleCurrentChange(val) {
      this.zsDetailSettings.currentPage = val
      await this.getZsBodyData()
      await this.getZsHeadData()
    },
    // 表头数据
    async getZsHeadData() {
      try {
        this.zsDetailSettings.fdetailLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          // FRepKey: 30002
          FRepKey: 3000202
        })
        this.zsDetailSettings.fdetailLoading = false
        if (res.Error === 0) {
          if (res.Data.length) {
            // this.zsDetailSettings.detailFormThead = res.Data.slice(0, 8)
            // this.zsDetailSettings.detailFormThead = res.Data.slice(2, 8)
            this.zsDetailSettings.detailFormThead = res.Data
          } else {
            this.zsDetailSettings.detailFormThead = []
          }
        }
        // 机型  功率 生效台数 流水号
        this.zsDetailSettings.detailFormThead.map(item => {
          this.zsDetailSettings.fdetailList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.zsDetailSettings.fdetailData = this.zsDetailSettings.fdetailList.slice()
        // 获取显示表头键值对
        this.zsDetailSettings.detailFormThead.filter(item => {
          // if (!item.frephide) {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.zsDetailSettings.fdetailList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })
        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })
        // this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.zsDetailSettings.fdetailLoading = false
      }
    },
    // 表体数据————erp职员列表
    async getZsBodyData() {
      try {
        this.zsDetailSettings.fdetailLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.zsDetailSettings.fdetailKeyword,
          fstatus: this.zsDetailSettings.fstatus,
          limit: this.zsDetailSettings.pagesize,
          page: this.zsDetailSettings.currentPage,
          FRepKey: 30002
        })
        this.zsDetailSettings.fdetailLoading = false
        this.zsDetailSettings.fdetailList = res.Data
        this.zsDetailSettings.total = res.total
      } catch (error) {
        this.zsDetailSettings.fdetailLoading = false
      }
    },
    async cellDbClick(row, column, cell, event) {
      // console.log(column.id, column.property, column, row, event, 'column')
      // fcomDialog
      switch (column.property) {
        case 'fisjiazhang':
          this.fjzCom.row = row
          this.fjzCom.fmodel = row.fmodel
          this.fjzCom.fbrand = row.fbrand
          this.fjzCom.fjybjbillno = row.fbillno
          this.fjzCom.fbillnoentry = row.fbillnoentry
          this.fjzCom.fmodal = true
          await this.getvxetableBillConfig()
          await this.getvxetableGenList()

          break
        default:
          break
      }
    },
    // 添加表格背景颜色
    footerCellClassName({ $rowIndex, columnIndex }) {
      // if (columnIndex === 0) {
      if ($rowIndex === 0) {
        // return 'col-blue'
        // }
      }
    },
    async searchFcomData() {
      const data = {
        keyword: this.fcomDialog.fcomKeyword,
        FRepKey: this.fcomDialog.FRepKey,
        opername,
        data: this.fisJzDialog.dialogObj.row,
        // fdanweibumen: this.fcomDialog.fdanweibumen,
        fbrand: this.fcomDialog.fbrand,
        fmodel: this.fcomDialog.fmodel,
        fjzdetail: this.fcomDialog.fjzdetail,
        fjybjbillno: this.fcomDialog.fjybjbillno
      }
      await this.getBAOJIAMX(data)
    },
    async getBAOJIAMX(data) {
      try {
        this.fcomDialog.cjDetail.fdetailLoading = true
        const res = await FhouxuJZ(data)
        if (res.Error === 0) {
          this.fcomDialog.cjDetail.fdetailLoading = false

          this.fcomDialog.cjDetail.fdetailList = res.Data
          this.fcomDialog.cjDetail.total = res.total
        }
      } catch (error) {
        this.fcomDialog.cjDetail.fdetailLoading = false
      }
    },
    async fbaseSearch() {
      await this.getvxetableGenList()
    },
    closeFjzDialog() {
      this.fjzCom.row = ''
      this.fjzCom.fmodel = ''
      this.fjzCom.fbrand = ''
      this.fjzCom.fjybjbillno = ''
      this.fjzCom.fbillnoentry = ''

      this.fjzCom.fmodal = false

      this.fjzCom.oriColumnData = []
      this.fjzCom.columnData = []
      this.fjzCom.gridOptions.columns = []
      this.fjzCom.formThead = []
      this.fjzCom.gridOptions.data = []
    },
    // 字段
    async getvxetableBillConfig() {
      const res = await vxetableBillConfig({
        FUnControl: -1,
        opername: this.opername,
        FRepKey: 3001002,
        FRepPage: 1

      })
      this.fjzCom.oriColumnData = res.Data
      // setTimeout(() => {
      if (res.Data.length > 0) {
        this.fjzCom.columnData.push({
          type: 'seq',
          width: 50,
          fixed: 'left'
        })
        this.fjzCom.columnData.push({
          type: 'checkbox',
          width: 50,
          fixed: 'left'
        })

        for (let i = 0; i < res.Data.length; i++) {
          if (res.Data[i].frepfld === 'fstatus') {
            this.fjzCom.columnData.push({
              field: res.Data[i].frepfld,
              title: res.Data[i].frepcap,
              // formatter: this.formatFstatus,
              width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,
              // editRender: { name: 'input', attrs: { placeholder: '' }}
              slots: {
                // 使用 JSX 渲染
                default: ({ row }) => {
                  if (row.fstatus === 1) {
                    return [
                      <el-tag>审核</el-tag>
                    ]
                  }
                }
              }
            })
          } else {
            this.fjzCom.vxeDisabled = false
            if (res.Data[i].falign === 1) {
              if (res.Data[i].fisedit === 1) {
                this.fjzCom.vxeDisabled = true
              }
              this.fjzCom.columnData.push({
                field: res.Data[i].frepfld,
                title: res.Data[i].frepcap,

                headerAlign: 'left',
                align: 'right',

                width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,

                editRender: { name: 'input', attrs: { disabled: Boolean(res.Data[i].fisedit), placeholder: '' }}
              })
            } else {
              if (res.Data[i].fisedit === 1) {
                this.fjzCom.vxeDisabled = true
              }
              this.fjzCom.columnData.push({
                field: res.Data[i].frepfld,
                title: res.Data[i].frepcap,
                // showHeaderOverflow: true,
                // showOverflow: true,
                // resizable: true,
                width: res.Data[i].frepwid > 0 ? res.Data[i].frepwid : 0,
                editRender: { name: 'input', attrs: { disabled: Boolean(res.Data[i].fisedit), placeholder: '' }}
              })
            }
          }
        }
        this.fjzCom.gridOptions.columns = this.fjzCom.columnData

        console.log(this.fjzCom.columnData, ' this.fjzCom.columnData')

        this.fjzCom.formThead = res.Data
        // this.tableList = []
        this.fjzCom.formThead.map(item => {
          this.fjzCom.gridOptions.data.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })

        this.fjzCom.header = []
        this.fjzCom.headerKeys = []
        // 获取显示表头键值对
        this.fjzCom.formThead.filter(item => {
          if (!item.frephide) {
            this.fjzCom.header.push(item.frepcap)
            this.fjzCom.headerKeys.push(item.frepfld)
          }
        })
      }
    },
    closeFcomDialog() {
      this.fisJzDialog = {
        dialogObj: {
          row: '',
          fbillno: '',
          fisqrname: 0, // 1 已完成
          fstatus: 0 // 1已审 0未审
        }, // 是否审核
        addUserModal: false,
        loadingForm: false,
        // rules: [],
        checkData: [],
        selectedData: [],
        form: {
          '数量': '',
          '备注': ''
        }
      }
      this.fcomDialog.fcomKeyword = ''
      this.fcomDialog.title = ''
      this.fcomDialog.FRepKey = 0
      this.fcomDialog.fdanweibumen = ''
      this.fcomDialog.fbrand = ''
      this.fcomDialog.fmodel = ''
      this.fcomDialog.fjybjbillno = ''
      this.fcomDialog.fmodal = false
    },
    exportDetailData(filename) {
      XLSXOBJ.ExportExcelData(['fcomTable'], filename)
    },
    handleFcomDialogChange(val) {
      console.log(val, ' val')
      this.fisJzDialog.checkData = []
      this.fisJzDialog.selectedData = val
      val.map(it => {
        this.fisJzDialog.checkData.push(it.fid)
      })
    },
    async delDialog() {
      // const data = this.fisJzDialog.selectedData[0]
      // console.log(data, ' data')

      if (Number(this.fisJzDialog.dialogObj.fstatus) === 1) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'error'
        })
        return
      }

      if (this.fisJzDialog.selectedData.length <= 0) {
        this.$message({
          message: '请选中要删除的行',
          type: 'warning'
        })
        return
      }

      try {
        const res = await FhouxuJZDel({
          FRepKey,
          row: this.fisJzDialog.dialogObj.row,
          fbillno: this.fisJzDialog.dialogObj.fbillno,
          data: this.fisJzDialog.selectedData,
          opername
        })
        if (res.Error === 0) {
          this.$message({
            type: 'success',
            message: res.Message
          })
          await this.getBAOJIAMX({
            keyword: this.fcomDialog.fcomKeyword,
            FRepKey: this.fcomDialog.FRepKey,
            opername,
            // fdanweibumen: this.fcomDialog.fdanweibumen,
            fbrand: this.fcomDialog.fbrand,
            fmodel: this.fcomDialog.fmodel,
            fjzdetail: this.fcomDialog.fjzdetail,
            fjybjbillno: this.fcomDialog.fjybjbillno
          })
          // this.fisJzDialog.addUserModal = false
        } else {
          this.$message({
            type: 'error',
            message: res.Message
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    async editDialog() {
      // fisJzDialog
      const data = this.fisJzDialog.selectedData[0]
      console.log(data, ' data')
      // return

      console.log(this.fisJzDialog.dialogObj, ' this.fisJzDialog.dialogObj')

      if (Number(this.fisJzDialog.dialogObj.fstatus) === 1) {
        this.$message({
          message: '已审核，不能修改！',
          type: 'error'
        })
        return
      }
      // this.editText = true
      this.fisJzDialog.form = {
        '数量': '',
        '备注': ''
      }
      if (this.fisJzDialog.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }

      this.fisJzDialog.addUserModal = true
      for (const i in data) {
        this.fisJzDialog.form[i] = data[i]
      }
      setTimeout(() => {
        this.$refs['formDialog'].clearValidate()
      })
    },
    async fisJzConfirm() {
      try {
        const res = await FhouxuJZSave({
          FRepKey,
          data: this.fisJzDialog.form,
          row: this.fisJzDialog.dialogObj.row,
          fbillno: this.fisJzDialog.dialogObj.fbillno,
          opername
        })
        if (res.Error === 0) {
          this.$message({
            type: 'success',
            message: res.Message
          })
          await this.getBAOJIAMX({
            keyword: this.fcomDialog.fcomKeyword,
            FRepKey: this.fcomDialog.FRepKey,
            opername,
            // fdanweibumen: this.fcomDialog.fdanweibumen,
            fbrand: this.fcomDialog.fbrand,
            fmodel: this.fcomDialog.fmodel,
            fjzdetail: this.fcomDialog.fjzdetail,
            fjybjbillno: this.fcomDialog.fjybjbillno
          })
          this.fisJzDialog.addUserModal = false
        } else {
          this.$message({
            type: 'error',
            message: res.Message
          })
        }
      } catch (error) {
        console.log(error)
      }
      console.log(this.fisJzDialog.form, ' this.fisJzDialog')
    },
    closeDialog() {
      this.importGrid.rows = ''
      this.importGrid.fbillno = ''
      this.importGrid.fmodel = ''
      this.importGrid.fbrand = ''
      this.importGridDel()
      this.$refs.fmdTable.clearSelection()
    },
    exportTableData() {
      const selectTemp = JSON.parse(JSON.stringify(this.selectedData))
      console.log(selectTemp, ' selectTemp', this.selectedData, ' this.selectedData')
      if (selectTemp.length <= 0 || selectTemp.length >= 2) {
        this.$message({
          message: '请选择一条数据',
          type: 'error'
        })
        return
      } else {
        if (Number(selectTemp[0].fstatus)) {
          this.$message({
            message: '该订单已审核，无法导入',
            type: 'error'
          })
          return
        } else {
          this.importGrid.fmodal = true
          this.importGrid.rows = this.selectedData[0]
          this.importGrid.fbillno = this.selectedData[0].fbillno
          this.importGrid.fmodel = this.selectedData[0].fmodel
          this.importGrid.fbrand = this.selectedData[0].fbrand
          this.importGridDel()
        }
      }

      // this.importGrid.data = this.selectedData
      // setTimeout(() => {
      //   console.log(this.selectedData, ' this.selectData')
      //   this.$refs[this.importGrid.excelRefs].open()
      // }, 0)
    },
    // 获取数据
    uploadExamFile(data) {
      console.log('导出的数据', data)
      this.importGrid.data = data
    },
    importData() {
      this.importGrid.fmodal = true
      this.importGridDel()
    },
    toImport() {
      this.$refs[this.importGrid.excelRefs].open()
    },
    importGridAdd() { // 新增
      const $grid = this.$refs[this.importGrid.gridRefs]
      $grid.insertAt(-1, -1)
    },
    importGridDel() { // 删除当前行
      const $grid = this.$refs[this.importGrid.gridRefs]
      if ($grid) {
        const checkData = $grid.getCheckboxRecords()
        if (checkData.length) {
          $grid.removeCheckboxRow()
        } else {
          this.importGrid.data = []
          $grid.remove($grid.getCheckboxRecords())
        }
      }
    },
    async importGridSave() { // 保存
      const $grid = this.$refs[this.importGrid.gridRefs]
      $grid.getRecordset()
      const { fullData } = $grid.getTableData()
      // console.log(tableData, ' importGridSave tableData')

      try {
        const res = await FYWImportJZ({
          FRepKey,
          fbillno: this.importGrid.fbillno,
          rows: this.importGrid.rows,
          opername: this.opername,
          fmodel: this.importGrid.fmodel,
          fbrand: this.importGrid.fbrand,
          data: fullData
        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          this.importGrid.rows = ''
          this.importGrid.fbillno = ''
          this.importGrid.fmodel = ''
          this.importGrid.fbrand = ''
          this.importGridDel()
          this.importGrid.fmodal = false
          this.$refs.fmdTable.clearSelection()
          // console.log(this.importGrid, ' this.importGrid')
        } else {
          this.$message({
            message: res.Message,
            type: 'error'
          })
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 导入数据上面----------------
    // 刷新
    refresh() {
      window.location.reload()
    },
    async vxeSendSms() {
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要通知的一行',
          type: 'warning'
        })
        return
      }
      this.dialogSendMsgModal = true
      await this.getBeijianTree()
    },
    async getBeijianTree() {
      try {
        this.sendMsgLoading = true
        const res = await beijianTree({
          opername: decodeURIComponent(this.globalDb.fname)
        })
        console.log(res, ' res')
        this.sendUsrList = res.Data
        this.sendMsgLoading = false
      } catch (error) {
        this.sendMsgLoading = false
        console.log(error)
      }
    },
    async confirmSendMsg() {
      const selectMsgArr = this.$refs.selectTree.getCheckedKeys(true)
      console.log(selectMsgArr, ' selectMsgArr')
      // this.dialogSendMsgModal = true
      try {
        const fcontent = this.formSendMsg.fcontent
        const fbillno = this.selectedData[0].fbillno
        if (selectMsgArr.length) {
          const fid = selectMsgArr.join(',')
          if (!fid) {
            this.$message({
              message: '手机号为空',
              type: 'error'
            })
            return
          }
          const res = await sendsms({
            opername: decodeURIComponent(this.globalDb.fname),
            fid,
            fcontent,
            fbillno
          })
          console.log(res, ' res')
          if (res.Error === 0) {
            this.mulSendMsgSelect = []
            this.formSendMsg.fcontent = ''
            this.dialogSendMsgModal = false
          }
        } else {
          this.$message({
            message: '未选中发送信息通知人员',
            type: 'error'
          })
          return
        }
      } catch (error) {
        this.dialogSendMsgModal = false
      }
    },
    async toDetail(data) {
      this.detailVisible = true
      this.detail = data
    },

    selectFBirthday(val) {
      this.form.fbirthday = parseTime(val, '{y}-{m}-{d}')
    },
    selectFHireDate(val) {
      this.form.fhiredate = parseTime(val, '{y}-{m}-{d}')
    },
    selectFLeaveDate(val) {
      this.form.fleavedate = parseTime(val, '{y}-{m}-{d}')
    },
    // -----------------上传开始---------------------
    beforeAvatarUpload(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUpload() {
      this.$refs.upload.submit()
    },

    handleRemove(file, fileList) {

    },
    handlePreview(file) {

    },
    exceed() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },
    notice(e) {
      if (e.code === 200) {
        this.$message(e.message)
      } else {
        this.$message(e.message)
      }
    },
    // -----------------上传结束---------------------
    // 表头数据
    async getAllHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data

        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        // this.tableData = this.tableList.slice()
        let tableTemp
        if (this.selectedData.length) {
          tableTemp = this.selectedData
        } else {
          tableTemp = this.tableList.slice()
        }

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        // const listData = this.tableList.slice()
        const listData = tableTemp.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getAllBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,

          fstatus: this.fstatus,
          limit: this.total,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },
    // 导出数据
    async downData() {
      await this.getAllBodyData()
      await this.getAllHeadData()
      await this.exportData()
    },
    async getAllData() {
      await this.getBodyData()
      await this.getHeadData()
    },

    selectSettings(val) {
      if (val === 0) {
        this.settings()
      } else if (val === 1) {
        this.dialogSQL()
      }
    },
    settings() {
      this.configModal = true
      this.getTableConfig()
    },

    // 更新数据
    async getUpdateConfigData() {
      await this.getTableConfig()
      await this.getBodyData()
      await this.getHeadData()
    },

    // SQL修改/更新
    async dialogSQL() {
      this.dialogSQLModal = true
      try {
        const res = await apiSql({
          db: this.globalDb.db,
          opername,
          FRepKey
        })

        if (res.Error === 0) {
          this.formSQL.gzsql = res.Data
          this.formSQL.FRepKey = FRepKey
        }
        setTimeout(() => {
          this.$refs['formSQL'].clearValidate()
        })
      } catch (error) {
        // console.log(error)
      }
    },

    confirmSQL() {
      this.$refs['formSQL'].validate(async(valid) => {
        if (valid) {
          try {
            this.formSQL.db = this.globalDb.db
            this.formSQL.opername = opername
            const res = await apiFileSave(this.formSQL)
            if (res.Error === 0) {
              this.dialogSQLModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })
            } else {
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            // console.log(error)
          }
        } else {
          return false
        }
      })
    },

    // 设置表格字段--获取数据
    async getTableConfig() {
      try {
        this.configLoading = true
        const res = await tableConfig({
          db: this.globalDb.db,
          opername,
          key: FRepKey
        })

        this.configList = res.Data

        this.key = FRepKey
        this.configLoading = false
      } catch (error) {
        this.configLoading = false
      }
    },

    // 表头数据
    async getHeadData() {
      try {
        this.listLoading = true
        this.header = []
        this.headerKeys = []
        this.listData = []
        const res = await configColumn({
          db: this.globalDb.db,
          opername,
          FRepKey
        })
        this.listLoading = false
        this.formThead = res.Data
        this.oriColumnData = res.Data

        // this.tableList = []
        this.formThead.map(item => {
          this.tableList.map(it => {
            if (item.freptype === 131) {
              it[item.frepfld] = Number(it[item.frepfld]).toFixed(item.fdecplaces)
            }
          })
        })
        this.tableData = this.tableList.slice()

        // 获取显示表头键值对
        this.formThead.filter(item => {
          if (!item.frephide) {
            this.header.push(item.frepcap)
            this.headerKeys.push(item.frepfld)
          }
        })
        // 获取显示表体数据
        const listData = this.tableList.slice()
        listData.map((item, index) => {
          this.listData[index] = {}
          this.headerKeys.map(it => {
            this.listData[index][it] = item[it]
          })
        })

        // 去除内码
        const arr = res.Data.slice()
        arr.map((item, index) => {
          if (item.frepfld === 'fid') {
            arr.splice(index, 1)
          }
        })

        this.dialogThead = arr.filter(item => item.funcontrol !== 1)
      } catch (error) {
        this.listLoading = false
      }
    },

    // 表体数据————erp职员列表
    async getBodyData() {
      try {
        this.listLoading = true
        const res = await genList({
          db: this.globalDb.db,
          opername,
          keyword: this.keyword,

          fstatus: this.fstatus,
          limit: this.pagesize,
          page: this.currentPage,
          FRepKey
        })
        this.listLoading = false

        this.tableList = res.Data
        this.total = res.total
      } catch (error) {
        this.listLoading = false
      }
    },

    async searchUser() {
      await this.getAllData()
    },
    async handleSizeChange(val) {
      this.currentPage = 1
      this.pagesize = val
      await this.getAllData()
    },
    async handleCurrentChange(val) {
      this.currentPage = val
      await this.getAllData()
    },
    salaryCurrentChange(val) {
      this.curData = val
    },

    // 下载
    async handleDownload() {
      const res = await downFileUrl({
        db: this.globalDb.db,
        opername,
        FRepKey
      })
      if (res.Error === 0) {
        this.tableSetExcel = true
        this.url = res.Data
      } else {
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }
    },

    downloadFile1() {
      this.tableSetExcel = false
      window.open('/api/downloadFile?FRepKey=' + FRepKey)
    },

    // -----------------上传模板开始---------------------
    beforeAvatarUploadBasic(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls' || testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!extension) {
        this.$message({
          message: '上传文件只能是 xls/xlsx格式!',
          type: 'warning'
        })
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 1MB!',
          type: 'warning'
        })
      }

      const fd = new FormData()
      fd.append('file', file)

      if (extension) {
        return true
      } else {
        this.$message.warning('只能上传excel文件格式xls/xlsx')
        return false
      }
    },

    async submitUploadBasic() {
      this.$refs.uploadBasic.submit()
    },

    handleRemoveBasic(file, fileList) {

    },
    handlePreviewBasic(file) {

    },
    exceedBasic() {
      // 重复选择文件,弹出错误弹窗
      this.$message('最多仅支持上传一个文件')
    },

    noticeBasic(e) {
      if (e.Error === 0) {
        this.$message(e.Message)
        this.getAllData()
        this.$refs.uploadBasic.clearFiles()
      } else {
        this.$message(e.Message)
      }
    },

    // 添加
    async addUser() {
      this.$router.push('/baojia/marketHxAdd?key=30010')
      return
      // this.editText = false
      // this.form = {}
      // const data = {}

      // this.dialogThead.map(item => { data[item.frepfld] = '' })
      // for (const i in data) {
      //   this.$set(this.form, i, data[i])
      // }

      // this.form.ffax = this.setConfigData.fsetffax
      // setTimeout(() => {
      //   this.$refs['form'].clearValidate()
      // })

      // this.addUserModal = true
    },

    // 修改
    async editUser() {
      const data = this.selectedData[0]

      if (data && Number(data.fstatus) === 1) {
        this.$message({
          message: '已审核，不能修改！',
          type: 'error'
        })
        return
      }
      this.editText = true
      this.form = {}
      if (this.selectedData.length !== 1) {
        this.$message({
          message: '请选中要编辑的一行',
          type: 'warning'
        })
        return
      }
      console.log(data, 'data')

      this.$router.push('/baojia/marketHxAdd?key=30010&fid=' + data.fid)
    },
    async confirm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          this.loadingForm = true
          try {
            this.form.db = this.globalDb.db
            this.form.opername = opername
            this.form.FRepKey = FRepKey

            const res = await genAdd(this.form)
            if (res.Error === 0) {
              this.loadingForm = false
              this.addUserModal = false
              this.$message({
                message: res.Message,
                type: 'success'
              })

              await this.getAllData()
            } else {
              this.loadingForm = false

              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            this.loadingForm = false
          }
        } else {
          return false
        }
      })
    },

    async delUser() {
      const data = this.checkData
      if (data.length < 1) {
        this.$message({
          message: '请选中要删除的一行',
          type: 'warning'
        })
        return
      }
      const dataTemp = this.selectedData
      const isFstatus = dataTemp.filter(it => Number(it.fstatus) === 1)

      if (isFstatus.length) {
        this.$message({
          message: '已审核，不能删除！',
          type: 'error'
        })
        return
      }

      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        cancelButtonClass: 'btn-custom-cancel',
        type: 'warning'
      }).then(async() => {
        const fid = data.join(',')
        const res = await genDel({
          db: this.globalDb.db,
          opername,
          data: this.selectedData,
          fid: fid,
          FRepKey

        })
        if (res.Error === 0) {
          this.$message({
            message: res.Message,
            type: 'success'
          })
          await this.getAllData()
          return
        }
        this.$message({
          message: res.Message,
          type: 'error'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // 合计
    getSummaries({ columns, data }) {
      const sums = []
      const arr = []
      this.oriColumnData.forEach((item, itemIndex) => {
        if (item.frepfld && item.frepsum === 1) {
          arr.push(item.frepfld)
        }
      })
      columns.forEach((column, columnIndex) => {
        if (columnIndex === 0) {
          sums[columnIndex] = '合计'
        } else {
          if (arr.indexOf(column.property) >= 0) {
            sums[columnIndex] = this.sumNum(data, column.property).toFixed(2)
          } else {
            sums[columnIndex] = ''
          }
        }
      })
      // 返回一个二维数组的表尾合计
      return sums
    },

    sumNum(list, field) { // DONE
      let count = 0
      list.forEach(item => {
        count += Number(item[field]) * 100
      })
      return (count / 100)
    },

    // 1—审核，0—反审
    async check(Fstatus) {
      if (!this.checkData.length) {
        this.$message({
          message: '请选择表格行数据',
          type: 'error'
        })
        return
      }
      if (Number(Fstatus) === 1) {
        this.$confirm('是否审核, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          cancelButtonClass: 'btn-custom-cancel',
          type: 'warning'
        }).then(async() => {
          try {
            const res = await checkStatus({
              db: this.globalDb.db,
              opername: decodeURIComponent(this.globalDb.fname),
              loginname: decodeURIComponent(this.globalDb.fname),
              FRepKey,
              data: this.selectedData,
              Fstatus, // 1—审核，0—反审
              fid: this.checkData.join(',')

            })
            if (res.Error === 0) {
              this.$message({
                message: res.Message,
                type: 'success'
              })
              await this.getAllData()
            } else {
              this.loadingForm = false
              this.$message({
                message: res.Message,
                type: 'error'
              })
            }
          } catch (error) {
            console.log(error)
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
      } else {
        try {
          const res = await checkStatus({
            db: this.globalDb.db,
            opername: decodeURIComponent(this.globalDb.fname),
            loginname: decodeURIComponent(this.globalDb.fname),
            FRepKey,
            Fstatus, // 1—审核，0—反审
            fid: this.checkData.join(','),
            appname: '',
            data: this.selectedData
          })
          if (res.Error === 0) {
            this.$message({
              message: res.Message,
              type: 'success'
            })
            await this.getAllData()
          } else {
            this.loadingForm = false
            this.$message({
              message: res.Message,
              type: 'warning'
            })
          }
        } catch (error) {
          console.log(error)
        }
      }
    },

    handleSelectionChange(val) {
      console.log(val, ' val')
      this.checkData = []
      this.selectedData = val
      val.map(it => {
        this.checkData.push(it.fid)
      })
    }

  }
}

</script>
<style lang="scss" scoped>
.config-dialog ::v-deep .el-dialog {
  width: 90%;
}
 .import-set-modal, .cb-set-modal {
  .search-grid {
    margin-bottom: 10px;
  }
  ::v-deep .el-dialog__body {
    padding: 0 20px;
  }
}
  .cb-set-modal ::v-deep .el-dialog__body {
    min-height: 350px!important;
    overflow: scroll;
  }
  .cb-set-modal ::v-deep .single-select-table thead .el-table-column--selection .cell {
    display: none;
  }
  .config-dialog ::v-deep .el-dialog__body {
  padding: 0 20px;
  height: 600px;
}
</style>
